<template>
  <div class="container">
    <div class="opt-area-02">
      <div class="input-frame" style="width: 100%;text-alone:left;margin-bottom:10px;font-size: 14px">
        &nbsp;&nbsp;&nbsp;&nbsp;总人数: <span>{{params.totalRecord}}</span>
<!--         <div v-if="severUserInfo.company_grade === '5'-->
<!--         || ( params.community_id-->
<!--         && usertypeNum !== 0 )">-->
<!--           ｜ 常住人数: <span>{{usertypeNum}}</span>-->
<!--&lt;!&ndash;           |&ndash;&gt;-->
<!--&lt;!&ndash;           居住人数: <span>{{juzhuNum}}</span>&ndash;&gt;-->
<!--         </div>-->
      </div>
      <div class="left-con">
        <div class="input-frame" style="width: 164px">
          <Input type="text" @on-click="selectlist(1)" placeholder="请输入姓名" style="width: 164px" v-model="params.name"
                 icon="ios-search"/>
        </div>
        <div class="input-frame" style="width: 164px">
          <Input type="text" @on-click="selectlist(1)" placeholder="请输入身份证号" style="width: 164px" v-model="params.cardno"
                 icon="ios-search"/>
        </div>
        <div class="input-frame" style="width: 164px">
          <Input type="text" @on-click="selectlist(1)" placeholder="请输入联系方式" style="width: 164px" v-model="params.mobile"
                 icon="ios-search"/>
        </div>
        <div class="input-frame" style="width: 164px" v-if="severUserInfo.company_grade!=='5'">
          <Select placeholder="请选择区" :disabled="Adisabled" v-model="params.area_id" style="width:164px" clearable @on-change="findDistrictList(3,params.area_id)" @on-clear="clearMsg(3)">
            <Option v-for="item in List1" :value="item.id" :key="item.id">{{ item.name }}</Option>
          </Select>
        </div>
        <div class="input-frame" style="width: 164px" v-if="severUserInfo.company_grade!=='5'">
          <Select placeholder="请选择街道" :disabled="Bdisabled" v-model="params.street_id" style="width:164px" clearable @on-change="findDistrictList(4,params.street_id)" @on-clear="clearMsg(4)">
            <Option v-for="item in List2" :value="item.id" :key="item.id">{{ item.name }}</Option>
          </Select>
        </div>
        <div class="input-frame" style="width: 164px" v-if="severUserInfo.company_grade!=='5'">
          <Select placeholder="请选择社区" v-model="params.community_id" style="width:164px" clearable>
            <Option v-for="item in List3" :value="item.id" :key="item.id">{{ item.name }}</Option>
          </Select>
        </div>
        <Button type="info" size="small" @click="selectlist(1)" style="margin-top: 5px;margin-right:5px">搜索</Button>
        <Button type="success" size="small" @click="addPerson(1)" style="margin-top: 5px;margin-right:5px">添加</Button>
        <Button type="success" size="small" @click="withCard2" style="margin-top: 5px;margin-right:5px">识别身份证</Button>
        <Button type="primary" size="small" style="margin-top: 5px;margin-right:5px" @click="importModal1=true">导入信息</Button>
        <Button type="error" size="small" style="margin-top: 5px;margin-right:5px" @click="importModal2=true">下载模板</Button>
        <Button type="primary" v-if="severUserInfo.company_code === 'LM00006'" size="small" style="margin-top: 5px;margin-right:5px" @click="importModal3=true">导出信息</Button>
        <Button type="info" size="small" style="margin-top: 5px;margin-right:5px" @click="focusGroupModel=true">选择人员标签</Button>
        <Modal
          v-model="importModal1"
          title="导入信息">
          <div>
            <Tag color="error" size="medium">提示：一次不要导入过多数据</Tag>
          </div>
          <Button type="primary" size="small" style="margin-top: 5px;margin-right:5px" @click="importExcel">导入网格人员信息</Button>
<!--          <Button type="primary" size="small" style="margin-top: 5px;margin-right:5px" @click="importTsPeopleExcel">导入重点人群信息</Button>-->
          <Button type="primary" size="small" style="margin-top: 5px;margin-right:5px" @click="importTsPeopleExcelNew">导入重点人群信息(新)</Button>
<!--          <Button type="primary" size="small" style="margin-top: 5px;margin-right:5px" @click="importFr">导入法人信息</Button>-->
<!--          <Button type="primary" size="small" style="margin-top: 5px;margin-right:5px" @click="importSw">导入死亡信息</Button>-->
        </Modal>
        <Modal
          v-model="importModal2"
          title="下载模板">
            <Button type="error" size="small" style="margin-top: 5px;margin-right:5px"><a :href="excelTemplate1">下载网格人员模板</a></Button>
<!--            <Button type="error" size="small" style="margin-top: 5px;margin-left: 5px"><a :href="excelTemplate2">下载法人信息模板</a></Button>-->
<!--            <Button type="error" size="small" style="margin-top: 5px;margin-left: 5px"><a :href="excelTemplate3">下载死亡信息模板</a></Button>-->
<!--            <Button type="error" size="small" style="margin-top: 5px;margin-right:5px"><a :href="excelTemplate4">下载重点人群模板</a></Button>-->
            <Button type="error" size="small" style="margin-top: 5px;margin-right:5px"><a :href="excelTemplate5">下载重点人群模板(新)</a></Button>

        </Modal>
        <Modal
          v-model="importModal3"
          title="导出信息">
          <Button type="primary" size="small" style="margin-top: 5px;margin-right:5px" @click="getExcel">导出网格入户人员信息</Button>
        </Modal>
        </div>
      <div class="left-con" style="margin-top: 5px">
        <div class="input-frame" style="width: 164px" v-if="severUserInfo.company_grade === '5'">
          <Select placeholder="请选择网格" v-model="params.garden_id" style="width:164px" clearable @on-change="findGridBuildingList(params.garden_id)" @on-clear="clearGrid(6)">
            <Option v-for="item in GridGradenList" :value="item.id" :key="item.id">{{ item.name }}</Option>
          </Select>
        </div>
        <div class="input-frame" style="width: 164px" v-if="severUserInfo.company_grade === '5'">
          <Select placeholder="请选择楼" v-model="params.building_id" style="width:164px" clearable @on-change="findGridUnitList(params.building_id)" @on-clear="clearGrid(7)">
            <Option v-for="item in GridBuildingList" :value="item.id" :key="item.id">{{ item.name }}</Option>
          </Select>
        </div>
        <div class="input-frame" style="width: 164px" v-if="severUserInfo.company_grade === '5'">
          <Select placeholder="请选择单元" v-model="params.unit_id" style="width:164px" clearable @on-change="findGridFloorList(params.unit_id)" @on-clear="clearGrid(8)">
            <Option v-for="item in GridUnitList" :value="item.id" :key="item.id">{{ item.name }}</Option>
          </Select>
        </div>
        <div class="input-frame" style="width: 164px" v-if="severUserInfo.company_grade === '5'">
          <Select placeholder="请选择层" v-model="params.floor_id" style="width:164px" clearable @on-change="findGridDoorplateList(params.floor_id)" @on-clear="clearGrid(9)">
            <Option v-for="item in GridFloorList" :value="item.id" :key="item.id">{{ item.name }}</Option>
          </Select>
        </div>
        <div class="input-frame" style="width: 164px" v-if="severUserInfo.company_grade === '5'">
          <Select placeholder="请选择户" v-model="params.doorplate_id" style="width:164px" clearable @on-clear="clearGrid(10)">
            <Option v-for="item in GridDoorplateList" :value="item.id" :key="item.id">{{ item.name }}</Option>
          </Select>
        </div>
      </div>
      <div class="left-con" style="margin-top: 5px">
        <div class="input-frame" style="width: 164px" v-if="severUserInfo.company_grade === '5'">
          <Select placeholder="请选择空挂户类型" v-model="params.is_kgh" style="width:164px">
            <Option value="" >全部</Option>
            <Option value="0" >是</Option>
            <Option value="1" >否</Option>
          </Select>
        </div>
<!--        <div class="input-frame" style="width: 164px" v-if="severUserInfo.company_grade === '5'">-->
<!--          <Select placeholder="请选择常住类型" v-model="params.user_type" style="width:164px">-->
<!--            <Option value="" >全部</Option>-->
<!--            <Option value="0" >常住</Option>-->
<!--            <Option value="1" >流动</Option>-->
<!--          </Select>-->
<!--        </div>-->
        <div class="input-frame" style="width: 164px">
          <Select placeholder="请选择疫苗接种类型" v-model="params.ym" style="width:164px">
            <Option value="" >全部</Option>
            <Option value="yes">接种</Option>
            <Option value="no" >未接种</Option>
            <!--            <Option value="18" >未接种(18岁以上)</Option>-->
            <!--            <Option value="1218" >未接种(12岁到18岁)</Option>-->
            <!--            <Option value="12" >未接种(12岁以下)</Option>-->
          </Select>
        </div>
        <div class="input-frame" style="width: 164px">
          <Input v-model="params.ymAgeBegin" type="number" placeholder="请输入开始年龄" style="width: 164px" />
        </div>
        <div class="input-frame" style="width: 164px">
          <Input v-model="params.ymAgeEnd" type="number" placeholder="请输入结束年龄" style="width: 164px" />
        </div>
      </div>
      <div v-if="PickfocusGroupList.length > 0" class="left-con" style="margin-top: 5px">
          当前选择标签：<Tag v-for="(item,index) in PickfocusGroupList" :key="index">{{item.name}}</Tag>
<!--<div>-->
<!--          <Tree ref="focusGroupTree" :data="focusGroupList" show-checkbox></Tree>-->
<!--&lt;!&ndash;          <CheckboxGroup v-model="PickfocusGroupList">&ndash;&gt;-->
<!--&lt;!&ndash;            <Checkbox v-for="(item,index) in focusGroupList" :key="index"&ndash;&gt;-->
<!--&lt;!&ndash;                      :label="item.second_level_id"&ndash;&gt;-->
<!--&lt;!&ndash;                      v-if="item.is_click==='0' && item.second_level_id"&ndash;&gt;-->
<!--&lt;!&ndash;                      border>{{item.name}}</Checkbox>&ndash;&gt;-->
<!--&lt;!&ndash;          </CheckboxGroup>&ndash;&gt;-->
<!--</div>-->
      </div>
    </div>
    <Drawer title="选择人员标签" placement="left" :closable="false" v-model="focusGroupModel">
      <Tree ref="focusGroupTree" :data="focusGroupList" show-checkbox></Tree>
    </Drawer>
    <import-excel ref="child"></import-excel>
    <import-fr ref="fr"></import-fr>
    <import-sw ref="sw"></import-sw>
    <import-tspeople ref="tspeople"></import-tspeople>
    <import-tspeople-new ref="tspeoplenew"></import-tspeople-new>
    <Table :loading="countData.loading" border :columns="columns2" :data="DataList" size="small" ref="table">
      <template slot="doorplate_id" slot-scope="{ row }">
<!--        <span v-if="(row.doorplate_id===undefined || row.doorplate_id==='') && (row.is_kgh==='1' || row.is_kgh === undefined || row.is_kgh === '')">未入户</span>-->
<!--        <span v-else>已入户</span>-->
        <span>已入户</span>
      </template>
      <template slot="action" slot-scope="{ row }">
        <Row style="margin-bottom: 5px; margin-top: 2px">
          <Button class="table-action-btn" type="success" size="small" @click="fillUserInfo(row)">编辑</Button>
          <user-type-log :user-info="row"></user-type-log>
          <Button v-if="columns2.findIndex(item => item.key === 'reason') !== -1" style="margin-top: 3px" type="error" size="small" @click="createYmReasonModel(row)">填写疫苗未接种原因</Button>
        </Row>
      </template>
    </Table>
<!--    <Row v-if="loadData == true">-->
<!--      <Col class="demo-spin-col" span="8" offset="8">-->
<!--        <Spin fix>-->
<!--          <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>-->
<!--          <div>Loading</div>-->
<!--        </Spin>-->
<!--      </Col>-->
<!--    </Row>-->
    <Row type="flex" justify="end" class="page_style">
      <Page :current="params.pageNo" :total="params.totalRecord" show-sizer :page-size="params.pageSize" show-elevator
            @on-change="pageAction" @on-page-size-change="pageSizeChange"/>
    </Row>
    <person-info-modal :user-info="userInfo" :control-data="controlData" :severUserInfo="severUserInfo" ref="photo"></person-info-modal>
    <Modal v-model="controlData.show1" title="输入证件号码" width="500">
      <Row>
        <Col span="6" style="text-align: right; margin-right: 10px; margin-top: 6px;">证件号码:</Col>
        <Col span="14">
          <Input v-model="controlData.cardnoInput" placeholder=""></Input>
        </Col>
      </Row>
      <div slot="footer">
        <Button type="text" size="large" @click="controlData.show1=false">取消</Button>
        <Button type="primary" size="large" @click="withCardOK">确定</Button>
      </div>
    </Modal>
    <wl-equipment :file-path="filePath" :file-name="fileName" v-model="deviceUserInfo" @change1="change"
                  :type="device_type" :is-open="openNow" ref="wlEquipment" @img-result="imgResult"></wl-equipment>
    <Modal
      v-model="YmReasonInfo.modal"
      title="未接种疫苗原因"
      @on-ok="createYmReason">
      <template>
        <div style="padding-left: 20%">
          <Input v-model="YmReasonInfo.info.name" style="width: 300px;margin-bottom: 10px" disabled>
            <span slot="prepend">姓名</span>
          </Input>
          <Input v-model="YmReasonInfo.info.cardno" style="width: 300px;margin-bottom: 10px" disabled>
            <span slot="prepend">身份证号</span>
          </Input>
          <Input v-model="YmReasonInfo.reason" placeholder="请填写未接种疫苗原因" style="width: 300px;margin-bottom: 10px">
            <span slot="prepend"><span style="color: red">*</span>原因</span>
          </Input>
          是否异地接种疫苗
          <i-switch v-model="YmReasonInfo.is_ydjz" size="large" style="margin-bottom: 10px">
            <span slot="open">是</span>
            <span slot="close">否</span>
          </i-switch>
          <Upload v-if="YmReasonInfo.is_ydjz === true" multiple action="http://10.40.20.4:8081/api/uc/mzsc/uploadService/uploadPic"
                  :before-upload="beforeUpload">
            <Button icon="ios-cloud-upload-outline">上传图片</Button>
            <span style="margin-left: 50px">请上传小于2M的图片</span>
            <div><span style="color: red">*</span>上传疫苗凭证图片前，请严格检查图片内容！</div>
          </Upload>
          <img :src="YmReasonInfo.jzpz" style="width: 100%"/>
        </div>
      </template>
    </Modal>
  </div>
</template>

<script>
import { findUserList, userinfo, findSubordinateList, getAllPeopleNum, getUserListNum } from '@/api/eventlist'
import PersonInfoModal from '@/view/xian-page/mainv3/components/personInfoModal'
import { addUser } from '@/api/grid'
import ImportExcel from '../components/import-excel'
import ImportFr from '../components/import-fr'
import ImportSw from '../components/import-sw'
import { idcard2 } from '@/api/idcard'
import {
  findBuildingXJList, findFloorXJList,
  findGardenList,
  findGardenXJList,
  // findGridModuleList,
  findModuleList, findUnitXJList, getAllPeopleJuZhuTypeNum, getAllPeopleUserTypeNum,
  getGridPeopleRHExcel, getJuZhuTypeNumList, getUserTypeNumList, saveUserYmReason
} from '../../../../api/eventlist'
import ImportTspeople from '../components/import-tspeople'
import ImportTspeopleNew from '../components/import-tspeople-new'
import WlEquipment from '@/components/wl-equipment/index'
import UserTypeLog from '../../mainv3/components/userTypeLog'
import { createUpLoadFiles, getSign } from '../../../../api/common'

export default {
  name: 'someuserlist',
  components: {
    UserTypeLog,
    ImportTspeopleNew,
    ImportTspeople,
    ImportSw,
    ImportFr,
    ImportExcel,
    PersonInfoModal,
    WlEquipment
  },
  data () {
    return {
      YmReasonInfo: {
        modal: false,
        info: {},
        reason: '',
        is_ydjz: false,
        jzpz: ''
      },
      usertypeNum: 0,
      juzhuNum: 0,
      focusGroupModel: false,
      PickfocusGroupList: [],
      focusGroupList: [],
      openNow: false,
      fileName: 'photo.png',
      device_type: '',
      filePath: '',
      deviceUserInfo: {},
      importModal1: false,
      importModal2: false,
      importModal3: false,
      // excelTemplate1: 'http://imgdl.tripln.top/webhdfs/v1/importTemplate/网格人员导入模板_5711809728.xlsx?op=OPEN&namenoderpcaddress=hadoop01:9000&offset=0',
      // excelTemplate1: 'http://imgdl.tripln.top/webhdfs/v1/importTemplate/网格人员导入模板v5_1094947727.xlsx?op=OPEN&namenoderpcaddress=hadoop01:9000&offset=0',
      excelTemplate1: 'http://imgdl.tripln.top/webhdfs/v1/importTemplate/网格人员导入模板v6_5667287254.xlsx?op=OPEN&namenoderpcaddress=hadoop01:9000&offset=0',
      excelTemplate2: 'http://imgdl.tripln.top/webhdfs/v1/importTemplate/法人信息导入模板_0293234585.xlsx?op=OPEN&namenoderpcaddress=hadoop01:9000&offset=0',
      excelTemplate3: 'http://imgdl.tripln.top/webhdfs/v1/importTemplate/死亡信息模板_3361116231.xlsx?op=OPEN&namenoderpcaddress=hadoop01:9000&offset=0',
      excelTemplate4: 'http://imgdl.tripln.top/webhdfs/v1/importTemplate/重点人群导入模板_6201064839.xlsx?op=OPEN&namenoderpcaddress=hadoop01:9000&offset=0',
      excelTemplate5: 'http://imgdl.tripln.top/webhdfs/v1/importTemplate/重点人群人员信息导入模板v2.0_7152027582.xlsx?op=OPEN&namenoderpcaddress=hadoop01:9000&offset=0',
      Adisabled: false,
      Bdisabled: false,
      loadData: true,
      loading: false,
      modalStr: '',
      id: '',
      row: {},
      countData: { loading: false },
      params: {
        name: '',
        pageNo: 1,
        pageSize: 10,
        totalRecord: 0,
        cardno: '',
        mobile: '',
        area_id: '',
        street_id: '',
        community_id: '',
        garden_id: '',
        building_id: '',
        unit_id: '',
        floor_id: '',
        doorplate_id: '',
        is_kgh: '',
        ym: '',
        ymAgeBegin: '',
        ymAgeEnd: '',
        user_type: ''
      },
      columns2: [
        { title: '姓名',
          key: 'name',
          // width: 100,
          align: 'center' },
        { title: '联系方式',
          key: 'mobile',
          // width: 120,
          align: 'center' },
        { title: '身份证号',
          key: 'TMcardno',
          // width: 160,
          align: 'center' },
        { title: '性别',
          key: 'sex',
          // width: 80,
          align: 'center' },
        // { title: '具体地址', key: 'present_address', minWidth: 250, align: 'center' },
        // { title: '是否入户', slot: 'doorplate_id', width: 100, align: 'center' },
        { title: '操作', align: 'center', width: 160, slot: 'action', fixed: 'right' }
      ],
      DataList: [],
      userOverall: {},
      controlData: {
        show1: false,
        uploadHeader: false,
        readType: 1, // 读取当前人员信息的方式 0未读取 1输入卡号 2读身份证 3人脸对比
        cardnoInput: '',
        showDetail: false,
        photo: '',
        personTags: []
      },
      userInfo: {},
      severUserInfo: {},
      List1: [],
      List2: [],
      List3: [],
      url: '',
      GridGradenList: [],
      GridBuildingList: [],
      GridUnitList: [],
      GridFloorList: [],
      GridDoorplateList: [],
      upPicData: {
        fileName: '疫苗凭证',
        filePath: '/grid/ym/pz'
      }
    }
  },
  methods: {
    beforeUpload (file) {
      this.upPicData.fileName = this.upPicData.fileName + '.' + file.type.substring(6)
      let that = this
      const reader = new FileReader()
      reader.readAsDataURL(file)
      reader.onload = () => {
        let index = reader.result.indexOf('base64,') + 7
        that.upPicData.file = reader.result.substring(index)
        that.upPic(that.upPicData)
      }
      return false
    },
    upPic (obj) {
      var time = new Date().getTime()
      this.timeStep = time.toString()
      let param = {
        filePath: obj.filePath,
        fileName: obj.fileName,
        timestamp: this.timeStep
      }
      getSign(param).then(res => {
        if (res.data.errcode === 0) {
          createUpLoadFiles(res.data.data.docking_url, {
            sign: res.data.data.sign,
            timestamp: this.timeStep,
            filePath: obj.filePath,
            fileName: obj.fileName,
            file: obj.file
          }).then(res => {
            if (res.data.errcode === 0) {
              console.log(this.imgType, '照片类型')
              this.YmReasonInfo.jzpz = res.data.data
            } else {
              this.$Notice.error({ title: '上传失败', desc: res.data.data.msg })
            }
          })
        } else {
          this.$Notice.error({ title: '上传失败', desc: res.data.data.msg })
        }
      })
    },
    createYmReasonModel (e) {
      this.YmReasonInfo.modal = true
      this.YmReasonInfo.info = e
      this.YmReasonInfo.reason = e.reason
      this.YmReasonInfo.jzpz = e.jzpz
      if (e.is_ydjz === '1') {
        this.YmReasonInfo.is_ydjz = true
      } else {
        this.YmReasonInfo.is_ydjz = false
      }
    },
    createYmReason () {
      let data = {
        cardno: this.YmReasonInfo.info.cardno,
        reason: this.YmReasonInfo.reason,
        is_ydjz: this.YmReasonInfo.is_ydjz === true ? 1 : 0,
        jzpz: this.YmReasonInfo.jzpz
      }
      if (data.is_ydjz === 1) {
        if (data.jzpz === '' || data.jzpz === undefined) {
          this.$Notice.error({
            title: '保存失败！',
            desc: '请上传疫苗凭证！'
          })
          return
        }
      }
      saveUserYmReason(data).then(ret => {
        if (ret.data.errcode === 0) {
          this.$Notice.success({
            title: '保存成功！',
            desc: ret.data.errmsg
          })
          this.getList()
        } else {
          this.$Notice.error({
            title: '保存失败！',
            desc: ret.data.errmsg
          })
        }
      })
    },
    withCardOption (e) {
      console.log(e, 'bfbfbfbf')
      this.controlData.cardnoInput = ''
      let that = this
      getUserListNum({ cardno: e.idcard }).then(ret => {
        if (ret.data.errcode === 0) {
          if (ret.data.data.num > 0) {
            that.params.cardno = e.idcard
            that.getList()
          } else {
            console.log('meichadao')
            that.controlData.cardnoInput = e.idcard
            that.withCardOK()
          }
        } else {
          this.$Notice.error({
            title: '查询列表信息数量失败',
            desc: ret.data.errmsg
          })
        }
      })
    },
    imgResult (idcard) {
      this.getUserInfo(idcard)
      this.faceStatus = false
    },
    change (data, base64) {
      this.imgUrl = data.base64
      this.is_photo = true
    },
    // 刷身份证办理
    withCard2 () {
      this.controlData.readType = 2
      this.controlData.uploadHeader = true
      let that = this
      if (this.severUserInfo.email === 'JieYuDevice') {
        that.readIDCard(function (idcardinfo) {
          that.controlData.photo = 'data:image/png;base64,' + idcardinfo.PhotoBmp
          that.userOverall.name = idcardinfo.Name
          that.userOverall.address = idcardinfo.Address
          that.userOverall.sex = idcardinfo.Sex
          that.userOverall.folk = idcardinfo.Nation
          that.userOverall.card_type = '1'
          that.userOverall.idcard = IDCode
          that.withCardOption(that.userOverall)
        })
      } else {
        that.device_type = 'idcard'
        console.log(that.device_type, '类型哈哈哈哈')
        // that.$refs.wlEquipment.getResult()
        setTimeout(function () {
          console.log(that.deviceUserInfo.idcard, 'that.deviceUserInfo')
          that.controlData.photo = 'data:image/png;base64,' + that.deviceUserInfo.HeadPic
          that.userOverall.name = that.deviceUserInfo.name
          that.userOverall.address = that.deviceUserInfo.address
          that.userOverall.sex = that.deviceUserInfo.sex
          that.userOverall.folk = that.deviceUserInfo.folk
          that.userOverall.idcard = that.deviceUserInfo.idcard
          that.userOverall.card_type = '1'
          that.withCardOption(that.userOverall)
        }, 3000)
        // that.device_type = ''
        setTimeout(function () {
          that.device_type = ''
        }, 3000)
      }
    },
    // 读取身份证信息
    readIDCard (callback) {
      let that = this
      idcard2().then(data => {
        let result = data.data
        if (result.code === 'SUCCESS') {
          callback(result.result)
        } else {
          that.$Message.warning(result.message)
        }
      }).catch(err => {
        that.$Message.warning('没有找到读卡设备')
        console.log(err, '错误信息')
      })
    },
    getExcel () {
      getGridPeopleRHExcel().then(ret => {
        if (ret.data.errcode === 0) {
          window.open(ret.data.data.url)
        } else {
          this.$Notice.error({
            title: '获取失败',
            desc: ret.data.errmsg
          })
        }
      })
    },
    importTsPeopleExcelNew () {
      this.$refs.tspeoplenew.init()
    },
    importTsPeopleExcel () {
      this.$refs.tspeople.init()
    },
    importExcel () {
      this.$refs.child.init()
    },
    importFr () {
      this.$refs.fr.init()
    },
    importSw () {
      this.$refs.sw.init()
    },
    pageAction (page) {
      this.params.pageNo = page
      this.getList()
    },
    selectlist () {
      this.params.pageNo = 1
      this.getList()
    },
    getList () {
      this.countData.loading = true
      if (this.severUserInfo.company_grade === '2') {
        this.url = '/api/ac/grid/userRegisterService/findUserLMList'
        if ((this.params.area_id === '' || this.params.area_id === undefined) &&
          (this.params.street_id === '' || this.params.street_id === undefined) &&
          (this.params.community_id === '' || this.params.community_id === undefined)) {
          this.url = '/api/ac/grid/userRegisterService/findUserLMList'
        } else {
          this.url = '/api/as/grid/user/findUserList'
        }
      } else {
        this.url = '/api/as/grid/user/findUserList'
      }
      this.params.focusGroupList = []
      this.$refs.focusGroupTree.getCheckedNodes().forEach(item => {
        this.params.focusGroupList.push(item.second_level_id)
      })
      if (this.params.ymAgeBegin || this.params.ymAgeEnd) {
        var pattern = /[0-9]\d*/
        if (!pattern.test(this.params.ymAgeBegin)) {
          this.$Notice.error({
            title: '查询失败！！',
            desc: '开始年龄请输入数字！'
          })
          this.countData.loading = false
          return
        }
        if (!pattern.test(this.params.ymAgeEnd)) {
          this.$Notice.error({
            title: '查询失败！！',
            desc: '结束年龄请输入数字！'
          })
          this.countData.loading = false
          return
        }
      }
      if (this.params.ymAgeBegin) {
        if (!this.params.ymAgeEnd) {
          this.$Notice.error({
            title: '查询失败！！',
            desc: '结束年龄和开始年龄都需要选择！'
          })
          this.countData.loading = false
          return
          // /[1-9]\d*/
        }
      }
      if (this.params.ymAgeEnd) {
        if (!this.params.ymAgeBegin) {
          this.$Notice.error({
            title: '查询失败！！',
            desc: '开始年龄和结束年龄都需要选择！'
          })
          this.countData.loading = false
          return
        }
      }
      if (parseInt(this.params.ymAgeBegin) > parseInt(this.params.ymAgeEnd)) {
        this.$Notice.error({
          title: '查询失败！！',
          desc: '开始年龄需小于结束年龄！'
        })
        this.countData.loading = false
        return
      }
      console.log(this.params)
      findUserList(this.params, this.url).then(res => {
        if (res.data.errcode === 0) {
          this.DataList = res.data.data.results
          if (this.url === '/api/ac/grid/userRegisterService/findUserLMList') {
            this.getAllPeopleNum(this.params)
            // this.getAllPeopleUserTypeNum(this.params)
            // this.getAllPeopleJuZhuTypeNum(this.params)
          } else {
            this.getUserListNum(this.params)
            // this.getUserTypeNumList(this.params)
            // this.getJuZhuTypeNum(this.params)
            // this.params.totalRecord = res.data.data.totalRecord
          }
          if (this.params.ym === 'no') {
            // this.params.ym === '18' || this.params.ym === '1218' || this.params.ym === '12'
            if (this.columns2.findIndex(item => item.key === 'reason') === -1) {
              this.columns2.push({
                title: '疫苗未接种原因',
                key: 'reason',
                minWidth: 250,
                align: 'center'
              })
            }
          } else {
            if (this.columns2.findIndex(item => item.key === 'reason') !== -1) {
              this.columns2.splice(this.columns2.findIndex(item => item.key === 'reason'), 1)
            }
          }
        } else {
          this.$Notice.error({
            title: '查询列表信息失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    getAllPeopleUserTypeNum (e) {
      getAllPeopleUserTypeNum(e).then(ret => {
        if (ret.data.errcode === 0) {
          this.usertypeNum = ret.data.data.num
        } else {
          this.$Notice.error({
            title: '查询列表信息数量失败',
            desc: ret.data.errmsg
          })
        }
      })
    },
    getAllPeopleJuZhuTypeNum (e) {
      getAllPeopleJuZhuTypeNum(e).then(ret => {
        if (ret.data.errcode === 0) {
          this.juzhuNum = ret.data.data.num
        } else {
          this.$Notice.error({
            title: '查询列表信息数量失败',
            desc: ret.data.errmsg
          })
        }
      })
    },
    getUserTypeNumList (e) {
      getUserTypeNumList(e).then(ret => {
        if (ret.data.errcode === 0) {
          this.usertypeNum = ret.data.data.num
        } else {
          this.$Notice.error({
            title: '查询列表信息数量失败',
            desc: ret.data.errmsg
          })
        }
      })
    },
    getJuZhuTypeNum (e) {
      getJuZhuTypeNumList(e).then(ret => {
        if (ret.data.errcode === 0) {
          this.juzhuNum = ret.data.data.num
        } else {
          this.$Notice.error({
            title: '查询列表信息数量失败',
            desc: ret.data.errmsg
          })
        }
      })
    },
    getUserListNum (e) {
      getUserListNum(e).then(ret => {
        if (ret.data.errcode === 0) {
          this.params.totalRecord = ret.data.data.num
          this.countData.loading = false
        } else {
          this.$Notice.error({
            title: '查询列表信息数量失败',
            desc: ret.data.errmsg
          })
        }
      })
    },
    getAllPeopleNum (e) {
      getAllPeopleNum(e).then(ret => {
        if (ret.data.errcode === 0) {
          this.params.totalRecord = ret.data.data.num
          this.countData.loading = false
        } else {
          this.$Notice.error({
            title: '查询列表信息数量失败',
            desc: ret.data.errmsg
          })
        }
      })
    },
    pageSizeChange (e) {
      this.params.pageSize = e
      this.selectlist(this.params.pageNo)
    },
    // 完善用户信息
    fillUserInfo (item) {
      this.userOverall = item
      if (!this.userOverall.id) return
      this.getUserInfo(item.cardno)
      this.controlData.showDetail = true
    },
    getUserInfo (cardno) {
      this.controlData.cardno = cardno
      this.userOverall.cardno = cardno
      userinfo(cardno).then(res => {
        if (res.data.errcode === 0) {
          this.userInfo = res.data.data
          if (this.userInfo.photo === undefined) {
            this.userInfo.photo = ''
          }
          // this.$refs.photo.photoShow(this.userInfo.photo)
          if (this.userInfo.focus_group) {
            this.controlData.personTags = this.userInfo.focus_group.split(',')
          } else {
            this.controlData.personTags = []
          }
          // 不论是否上传头像，查询个人信息时包含头像则不上传
          if (this.userInfo.photo) {
            this.controlData.photo = this.userInfo.photo
            this.controlData.uploadHeader = false
          } else {
            this.controlData.photo = this.controlData.photo || this.nophoto
          }
          if (this.controlData.readType !== 2) {
            this.userOverall.name = this.userInfo.name
            this.userOverall.address = this.userInfo.address
            this.userOverall.sex = this.userInfo.sex
            this.userOverall.folk = this.userInfo.folk
          }
          this.userOverall.readCount++
          this.userOverall.id = this.userInfo.id
          this.userOverall.userInfo = this.userInfo
        } else {
          this.$Notice.error({ title: '查询失败！', desc: res.data.errmsg })
        }
      })
    },
    addPerson () { // 添加人员
      this.controlData.show1 = true
      this.controlData.cardnoInput = ''
    },
    withCardOK () { // 调取个人信息
      this.userInfo = {}
      this.getGridUserInfo(this.controlData.cardnoInput)
      this.controlData.show1 = false
    },
    getGridUserInfo (cardno) {
      this.controlData.cardno = cardno
      this.userOverall.cardno = cardno
      addUser({ cardno: cardno }).then(res => {
        if (res.data.errcode === 0) {
          if (res.data.data === null) {
            this.userInfo = { cardno: cardno }
            this.userInfo.card_type = 1
            this.controlData.personTags = []
            this.controlData.idsArr = []
            this.controlData.showDetail = true
          } else {
            this.controlData.showDetail = true
            this.userInfo = res.data.data
            if (this.userInfo.photo === undefined) {
              this.userInfo.photo = ''
            }
            if (this.userInfo.focus_group) {
              this.controlData.personTags = this.userInfo.focus_group.split(',')
            } else {
              this.controlData.personTags = []
            }
            // 不论是否上传头像，查询个人信息时包含头像则不上传
            if (this.userInfo.photo) {
              this.controlData.photo = this.userInfo.photo
              this.controlData.uploadHeader = false
            } else {
              this.controlData.photo = this.controlData.photo || this.nophoto
            }
            if (this.controlData.readType !== 2) {
              this.userOverall.name = this.userInfo.name
              this.userOverall.address = this.userInfo.address
              this.userOverall.sex = this.userInfo.sex
              this.userOverall.folk = this.userInfo.folk
            }
            this.userOverall.readCount++
            this.userOverall.id = this.userInfo.id
            this.userOverall.userInfo = this.userInfo
          }
        } else {
          this.$Notice.error({ title: '查询失败！', desc: res.data.errmsg })
          this.controlData.showDetail = false
        }
      })
    },
    findDistrictList (e1, e2) {
      let data = {
        grade: e1,
        id: e2
      }
      findSubordinateList(data).then(ret => {
        if (ret.data.errcode === 0) {
          if (e1 === 2) {
            this.List1 = ret.data.data
          } else if (e1 === 3) {
            this.List2 = ret.data.data
          } else if (e1 === 4) {
            this.List3 = ret.data.data
          }
        } else {
          this.$Notice.error({
            title: '查询失败',
            desc: ret.data.errmsg
          })
        }
      })
    },
    clearMsg (e1) {
      if (e1 === 3) {
        this.params.area_id = ''
        this.params.street_id = ''
        this.params.community_id = ''
      } else if (e1 === 4) {
        this.params.street_id = ''
        this.params.community_id = ''
      }
    },
    clearGrid (e) {
      if (e === 6) {
        this.params.garden_id = ''
        this.params.building_id = ''
        this.params.unit_id = ''
        this.params.floor_id = ''
        this.params.doorplate_id = ''
      } else if (e === 7) {
        this.params.building_id = ''
        this.params.unit_id = ''
        this.params.floor_id = ''
        this.params.doorplate_id = ''
      } else if (e === 8) {
        this.params.unit_id = ''
        this.params.floor_id = ''
        this.params.doorplate_id = ''
      } else if (e === 9) {
        this.params.floor_id = ''
        this.params.doorplate_id = ''
      } else if (e === 10) {
        this.params.doorplate_id = ''
      }
    },
    findGridGradenList () {
      findGardenList().then(ret => {
        if (ret.data.errcode === 0) {
          this.GridGradenList = ret.data.data
        } else {
          this.$Notice.error({ title: '获取失败', desc: ret.data.errmsg })
        }
      })
    },
    findGridBuildingList (e) {
      let data = {
        id: e
      }
      findGardenXJList(data).then(ret => {
        if (ret.data.errcode === 0) {
          this.GridBuildingList = ret.data.data
        } else {
          this.$Notice.error({ title: '获取失败', desc: ret.data.errmsg })
        }
      }
      )
    },
    findGridUnitList (e) {
      let data = {
        id: e
      }
      findBuildingXJList(data).then(ret => {
        if (ret.data.errcode === 0) {
          this.GridUnitList = ret.data.data
        } else {
          this.$Notice.error({ title: '获取失败', desc: ret.data.errmsg })
        }
      })
    },
    findGridFloorList (e) {
      let data = {
        id: e
      }
      findUnitXJList(data).then(ret => {
        if (ret.data.errcode === 0) {
          this.GridFloorList = ret.data.data
        } else {
          this.$Notice.error({ title: '获取失败', desc: ret.data.errmsg })
        }
      })
    },
    findGridDoorplateList (e) {
      let data = {
        floor_id: e
      }
      findFloorXJList(data).then(ret => {
        if (ret.data.errcode === 0) {
          this.GridDoorplateList = ret.data.data
        } else {
          this.$Notice.error({ title: '获取失败', desc: ret.data.errmsg })
        }
      })
    },
    findGridModuleList () {
      findModuleList().then(ret => {
        this.focusGroupList = ret.data.data
      })
    }
  },
  mounted () {
    this.severUserInfo = this.$store.state.user.severUserInfo
    this.getList()
    this.findGridModuleList()
  },
  watch: {
    'severUserInfo.company_grade' (val) {
      if (val === '2') {
        this.findDistrictList(2, '999999999')
      } else if (val === '3') {
        this.findDistrictList(2, '999999999')
        this.params.area_id = this.severUserInfo.company_id
        this.findDistrictList(3, this.params.area_id)
        this.Adisabled = true
      } else if (val === '4') {
        this.findDistrictList(2, '999999999')
        this.params.area_id = this.severUserInfo.parent_id
        this.findDistrictList(3, this.params.area_id)
        this.params.street_id = this.severUserInfo.company_id
        this.findDistrictList(4, this.params.street_id)
        this.Adisabled = true
        this.Bdisabled = true
      } else if (val === '5') {
        this.findGridGradenList()
      }
    },
    focusGroupModel (val) {
      if (!val) {
        this.PickfocusGroupList = []
        this.PickfocusGroupList = this.$refs.focusGroupTree.getCheckedNodes()
      }
    }
  }
}
</script>

<style scoped>
  .page_style {
    margin: 20px 5px;
  }

  .input-frame {
    width: 120px;
    margin-right: 10px;
    float: left;
  }

  .house-list > .group {
    background: white;
    padding: 10px;
    margin-top: 10px;
  }

  .house-list > .group > .item {
    border-bottom: 1px solid #f5f5f5;
    padding: 10px 0;
  }

  .house-list > .group > .item .top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
  }

  .house-list > .group > .item .title {
    font-size: 14px;
    color: #333333;
  }

  .house-list > .group > .item .address {
    font-size: 12px;
    color: gray;
    display: flex;
    align-items: center;
  }

  .house-list > .group > .item .detail {
    font-size: 12px;
    color: dodgerblue;
  }

  .opt-area-02 {
    display: flex;
    align-items: center;
    flex-direction: column;
    border: 1px solid #abdcff;
    background-color: #f0faff;
    padding: 8px 16px 8px 16px;
    border-radius: 4px;
    margin-bottom: 10px;
  }

  .opt-area-02 .right-con {
    width: 100%;
    margin-top: 5px;
    display: flex;
  }

  .opt-area-02 .left-con {
    font-size: 14px;
    width: 100%;
  }

  .opt-area-02 .left-con span {
    font-weight: bold;
  }

  .opt-area-02 .right-con input {
    width: 150px;
    margin-right: 10px;
  }

  .opt-area-02 .right-con .input-frame {
    width: 200px;
    margin-right: 10px;
  }

  .table-action-btn {
    margin-bottom: 3px;
  }

  .container >>> .ivu-btn-small {
    height: 24px;
    padding: 0 5px;
    font-size: 12px;
    border-radius: 3px;
  }

  .btn-action {
    margin-bottom: 10px;
  }

  .mp10 {
    margin-right: 10px;
  }
  .title-style {
    color: red;
  }
  .mb20 {
    margin-bottom: 20px;
  }
  .ivu-table-row {
    height: 57px;
  }
  .demo-spin-icon-load{
    animation: ani-demo-spin 1s linear infinite;
  }
  @keyframes ani-demo-spin {
    from { transform: rotate(0deg);}
    50%  { transform: rotate(180deg);}
    to   { transform: rotate(360deg);}
  }
  .demo-spin-col{
    height: 100px;
    position: relative;
    /*border: 1px solid #eee;*/
  }
  .container>>>.ivu-icon-ios-arrow-forward:before{
    color: black;
  }
</style>
